<script setup lang="ts">
import { confirmMessageBox } from "./components/message-box/index";
import { ElMessage, ElButton } from "element-plus";

const remove = () => {
  let time = 0
  confirmMessageBox({ title: '确认删除？', message: '您确定要删除该数据？' }).confirm((done) => {
    console.log('删掉它！')
    if (time !== 0) {
      // 调用API或其他什么事，在合适的时机关闭弹窗
      done()
      ElMessage.success('API重试成功，弹窗关闭')
    } else {
      ElMessage.error('模拟API失败')
    }
    time++
  }).cancel(() => {
    console.log('取消了')
  })
}
</script>

<template>
  <el-button @click="remove">删除</el-button>
</template>
